Improve autocompletion of test items
authorErcan Erden <ercerden@gmail.com>
Sat, 13 Jun 2015 20:34:14 +0000 (16:34 -0400)
committerErcan Erden <ercerden@gmail.com>
Sat, 13 Jun 2015 23:03:24 +0000 (19:03 -0400)
Test item autocompletion didn't work because it required the name of the
test to come immediately after [[test]] line. This commit should fix
that.

src/etc/_cargo

index f80a3211ec43d2cba2d51a564e8b05fdad94d8e2..314b282ce0365077c9808d7830341527f6bbec44 100644 (file)
@@ -1,4 +1,5 @@
 #compdef cargo
+
 typeset -A opt_args
 autoload -U regexp-replace
 
@@ -303,26 +304,48 @@ regexp-replace manifest '\{"root":"|"\}' ''
 echo $manifest
 }
 
-#gets test names from the manifest file
-_test_names(){
-local -a filelist;
-local manifest=$(_locate_manifest)
-if ! [[ $manifest ]]; then
-    return 0
-fi
-
-local last_line
-local -a tests;
-tests=()
-while read line
-do
-    if [[ $last_line == '[[test]]' ]]; then
-        regexp-replace line '^.*name *= *|"' ""
-        tests+=$line
+# Extracts the values of "name" from the array given in $1 and shows them as 
+# command line options for completion
+_get_names_from_array()
+{
+    local -a filelist;
+    local manifest=$(_locate_manifest)
+    if ! [[ $manifest ]]; then
+        return 0
     fi
-    last_line=$line
-done < $manifest
-_describe 'tests' tests
+
+    local last_line
+    local -a names;
+    local in_block=false
+    local block_name=$1
+    names=()
+    while read line
+    do
+        if [[ $last_line == "[[$block_name]]" ]]; then
+            in_block=true
+        else 
+            if [[ $last_line =~ '.*\[\[.*' ]]; then
+                in_block=false
+            fi
+        fi
+
+        if [[ $in_block == true ]]; then
+            if [[ $line =~ '.*name.*=' ]]; then
+                regexp-replace line '^.*name *= *|"' ""
+                names+=$line
+            fi
+        fi 
+
+        last_line=$line
+    done < $manifest
+    _describe $block_name names
+
+}
+
+#Gets the test names from the manifest file
+_test_names()
+{
+    _get_names_from_array "test"
 }
 
 _cargo